package com.china08.yxyapi.repository.db;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.china08.yxyapi.entity.db.res.YxyResResourceBookContent;

public interface YxyResResourceBookContentRepository extends JpaRepository<YxyResResourceBookContent, String> {
    YxyResResourceBookContent findByResourceIdAndBookContentId(String resId, String bookContent);

    List<YxyResResourceBookContent> findByResourceId(String resId);

    @Transactional
    @Modifying
    void deleteByResourceIdAndBookContentId(String resId, String string);

    @Query(value = " select distinct yrbk.bookId from YxyResResourceBookContent yrbk where  yrbk.phaseName = ?1  and  yrbk.semesterId = ?2  and  yrbk.subjectName = ?3 and yrbk.versionId = ?4 ")
    List<Object> getCharpter(String phaseName, String semesterId, String subjectName, String versionId);

    @Query(nativeQuery = true, value = " select distinct yrbk.book_id from yxy_res.yxy_res_resource_book_content yrbk where  yrbk.phase_name = ?1  and  yrbk.semester_id = ?2  and  yrbk.subject_name = ?3 and yrbk.version_id = ?4 and yrbk.book_content_id in (?5)")
    List<Object> getCharpter(String stage, String semester, String subjectName, String version, List<String> book2);

    List<YxyResResourceBookContent> findByBookContentId(String bookcontentId);

    @Query(nativeQuery = true, value = "select t1.* from yxy_res.yxy_res_resource_book_content t1 where FIND_IN_SET(?1,t1.book_content_pid)")
    List<YxyResResourceBookContent> findAllByBookContentPId(String bookcontentId);

}
